define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/sole/index',
                    add_url: 'user/sole/add',
                    edit_url: 'user/sole/edit',
                    del_url: 'user/sole/del',
                    import_url: 'user/sole/import',
                    import2_url: 'user/sole/import2',
                    multi_url: 'user/sole/multi',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true,operate:false},
                        // {field: 'group.name', title: __('Group')},
                        // {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        {field: 'gender_text', title: __('Gender'),operate:false},
                        {field: 'age_text', title: '年龄',operate:false},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'hospitalTotal', title: '签单医院',operate:false,formatter:function (value, row, index) {
                            var url = Table.api.replaceurl('hospital/hospital/salehospital?ids='+row.id || '', row, this.table);
                            return '<a href="' + Fast.api.fixurl(url) + '" class="dialogit" data-value="' + value + '" title="签单医院">' + value + '</a>';
                        }},
                        // {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        // {field: 'level', title: __('Level'), operate: 'BETWEEN', sortable: true},
                        // {field: 'score', title: __('Score'), operate: 'BETWEEN', sortable: true},
                        // {field: 'successions', title: __('Successions'), visible: false, operate: 'BETWEEN', sortable: true},
                        // {field: 'maxsuccessions', title: __('Maxsuccessions'), visible: false, operate: 'BETWEEN', sortable: true},
                        // {field: 'logintime', title: __('Logintime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'discount', title: '折扣', operate:false},
                        {field: 'createtime', title: __('Jointime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        // {field: 'joinip', title: __('Joinip'), formatter: Table.api.formatter.search},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden'),disabled:__('Disabled')}},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,buttons:[
                            {
                                name: '项目折扣',
                                title: '项目折扣',
                                classname: 'btn btn-xs btn-success btn-dialog',
                                icon: 'fa fa-bookmark',
                                url: 'matketing/sale_discount/index?id={ids}',
                                extend: 'data-area=\'["90%","90%"]\'',
                                visible: function (row) {
                                    return true;
                                }

                            }
                        ], formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});